# R 获取机器最大精度

addEpsEqual = function(eps, base = 2) { base + eps == base }
subEpsEqual = function(eps, base = 2) { base - eps == base }

findMachineAcc = function(func = addEpsEqual) {
    l = 0
    r = 1e-8
    m = (l + r) / 2

    while (TRUE) {
        p = m

        if (func(m)) {
            l = m
            m = (l + r) / 2
        } else {
            r = m
            m = (l + r) / 2
        }

        if (p == m)
            break
    }

    m
}

cat(sprintf('findMachineAcc(subEqsEqual): %s\n.Machine$double.neg.eps: %s\n',
            findMachineAcc(subEpsEqual), .Machine$double.neg.eps))
cat(sprintf('findMachineAcc(addEqsEqual): %s\n.Machine$double.eps: %s',
            findMachineAcc(addEpsEqual), .Machine$double.eps))
